extends "res://BaseEnemy.gd"

# 雪山狼特有属性
@export var frost_bite_chance = 0.3  # 霜咬几率
@export var frost_bite_damage = 2  # 霜咬每秒伤害
@export var frost_bite_duration = 3.0  # 霜咬持续时间
@export var pack_bonus = 0.2  # 每只同伴提供的伤害加成

func _ready():
	# 调用父类的_ready方法
	super._ready()
	
	# 设置雪山狼特有属性
	max_health = 40
	current_health = max_health
	movement_speed = 110.0
	damage = 10
	experience_value = 8
	
	# 更新生命值条
	if health_bar:
		health_bar.max_value = max_health
		health_bar.value = current_health
	
	# 设置外观
	if sprite:
		sprite.modulate = Color(0.9, 0.95, 1.0)  # 雪白色调

# 计算附近的狼数量
func count_nearby_wolves():
	var count = 0
	var wolves = get_tree().get_nodes_in_group("enemies")
	
	for wolf in wolves:
		if wolf != self and wolf.get_script().get_path() == get_script().get_path() and is_instance_valid(wolf):
			var distance = global_position.distance_to(wolf.global_position)
			if distance <= 150:  # 只计算150单位内的狼
				count += 1
	
	return count

# 重写攻击方法
func attack_player():
	# 计算伤害（考虑同伴加成）
	var pack_count = count_nearby_wolves()
	var pack_damage_bonus = 1.0 + (pack_count * pack_bonus)
	var actual_damage = damage * pack_damage_bonus
	
	# 播放攻击动画
	if animation_player and animation_player.has_animation("attack"):
		animation_player.play("attack")
	
	# 对玩家造成伤害
	if target_player and target_player.has_method("take_damage"):
		target_player.take_damage(actual_damage)
		
		# 尝试造成霜咬效果
		if randf() < frost_bite_chance:
			if target_player.has_method("apply_frost_bite_effect"):
				target_player.apply_frost_bite_effect(frost_bite_damage, frost_bite_duration)
			else:
				# 如果玩家没有霜咬方法，创建一个简单的霜咬效果
				var frost_effect = preload("res://FrostBiteEffect.tscn").instantiate()
				get_tree().get_root().add_child(frost_effect)
				frost_effect.target = target_player
				frost_effect.damage_per_tick = frost_bite_damage
				frost_effect.duration = frost_bite_duration
		
		print("雪山狼的攻击造成", actual_damage, "伤害!")
